<template id="notify">
    <div>
      <div style="padding:0;">
        <div style="margin-top:-30px; margin-bottom:-30px;padding:0px;">
             <el-input
                 placeholder="请输入内容"
                 prefix-icon="el-icon-search"
                 v-model="searchCon1" style="width:500px;">
            </el-input>
            <el-button type="primary" style="margin-left:100px;">搜索</el-button>
        </div>
      </div>
      <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="goods_id"
        label="ID"
        width="110">
      </el-table-column>
      <el-table-column
        prop="username"
        label="用户"
        width="110">
      </el-table-column>
      <el-table-column
        prop="goods_date"
        label="日期"
        width="110">
      </el-table-column>
      <el-table-column
        prop="goods_name"
        label="名称"
        width="110">
      </el-table-column>
      <el-table-column
        prop="goods_model"
        label="型号"
        width="110">
        </el-table-column>
        <el-table-column
        prop="goods_type"
        label="类型"
        width="110">
        </el-table-column>
        <el-table-column
        prop="address"
        label="地址"
        width="110">
        </el-table-column>
        <el-table-column
        prop="goods_num"
        label="库存"
        width="110">
        </el-table-column>
        <el-table-column
        prop="sendState"
        label="发货状态"
        width="110">
        </el-table-column>
        <el-table-column
          prop="accState"
          label="收货状态"
          width="110">
        </el-table-column>
         <el-table-column
          fixed="right"
          label="操作"
          width="110">
      <template slot-scope="scope">
        <el-button @click="deletePurchase(scope.$index,tableData)" type="text" size="small">删除</el-button>
        <el-button type="text" size="small" @click="sendGood(scope.row)" prop="sendG">发货</el-button>
      </template>
    </el-table-column>
    </el-table>
    </div>
</template>
<script>
export default {
    data(){
        return{
            tableData:this.$store.state.orderData,
            searchCon1:'',
            sendFlag:true
        }
    },
    methods:{
      deletePurchase(index,rows){
        let purchaseGoods = {
          'goods_id':rows[index].goods_id,
          'goods_model':rows[index].goods_model,
          'market_name':this.$store.state.marketName,
          'goods_sendState':rows[index].sendState,
          'goods_name':rows[index].goods_name,
          'user_name':rows[index].username
        };
        if(rows[index].sendState=="未发货" || rows[index].accState=="未收货"){
        this.$confirm('该订单可能未发货或者买家未收货，是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.axios.post("/api/shopping/deletePurchase.php",purchaseGoods).then(res=>{
            if(res.data=="ok"){
              rows.splice(index,1);
              this.$message({
              type: 'success',
              message: '删除成功!'
              });
            }else{
              this.$message({
                type:'success',
                message:'服务器出错了'
              });
            }
          });
          
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
        }else{
             this.axios.post("/api/shopping/deletePurchase.php",purchaseGoods).then(res=>{
            if(res.data=="ok"){
              rows.splice(index,1);
              this.$message({
              type: 'success',
              message: '删除成功!'
              });
            }else{
              this.$message({
                type:'success',
                message:'服务器出错了'
              });
            }
          });
        }
      },
      sendGood(row){
        let purchaseGoods = {
          'goods_id':row.goods_id,
          'goods_model':row.goods_model,
          'market_name':this.$store.state.marketName,
          'goods_sendState':row.sendState,
          'goods_name':row.goods_name,
          'user_name':row.username
        };
        if(row.sendG==true){
        this.axios.post("/api/shopping/sendGoods.php",purchaseGoods).then(res=>{
          console.log(res.data);
          if(res.data=="ok"){
            this.$message({
              type:'success',
              message:'发货成功'
            });
            row.sendG = false;
            row.sendState="已发货";
          }else if(res.data=="服务器出错"){
            this.$message({
              type:'success',
              message:'服务器出错了'
            });
          }else{
            this.$message({
              type:'success',
              message:'发货失败'
            });
          }
        });
        }else{
          this.$message({
            type:'success',
            message:'已经发过货了'
          });
        }
      }
    }
}
</script>